﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Utils.MVP;
using RMS.DataAccess.Entities;
using RMS.Web.Shell.View;
using RMS.Web.Shell.Presenter;
using RMS.Utils.Navigator;

namespace RMS.Account
{
    public partial class ProfileView : Page<ProfilePresenter>, IProfileView
    {
        Employees _employee;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillForm();
            }
        }
        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            Navigator.NavigateTo(Pages.Account_ChangePasswordView);
        }
        protected void btnSaveChages_Click(object sender, EventArgs e)
        {
            _employee = this.Presenter.getEmployeeInfo();
            if (_employee != null)
            {
                _employee.FirstName = txtFirstName.Text;
                _employee.FamilyName = txtFamilyName.Text;
                _employee.Email = txtEmail.Text;
                _employee.Mobile = txtMabile.Text;
                _employee.NameTitle = txtNameTitle.Text;
                _employee.Username = txtUsername.Text;
                _employee.Phone = txtPhone.Text;
                _employee.Address = txtAddress.Text;
                if (rdbMale.Checked)
                    _employee.gender = true;
                else
                    _employee.gender = false;

                if (this.Presenter.UpadateEmployee(_employee))
                    Notification.Show();
            }
            else
                Notification.Show("An error  occurred, Please try again later or call administrator");
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            FillForm();
        }
        private void FillForm()
        {
            _employee = this.Presenter.getEmployeeInfo();
            txtFirstName.Text = _employee.FirstName;
            txtFamilyName.Text = _employee.FamilyName;
            txtEmail.Text = _employee.Email;
            txtMabile.Text = _employee.Mobile;
            txtNameTitle.Text = _employee.NameTitle;
            txtUsername.Text = _employee.Username;
            txtPhone.Text = _employee.Phone;
            txtAddress.Text = _employee.Address;
            if (!_employee.gender)
                rdbFemale.Checked = true;
        }

    }
}